<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>网站导航</title>
		<%@ include file="../../../common/Admin-list.jsp"%> 	
 		<script type="text/javascript">
			$(function(){
				$('#tg').treegrid({									
					height:'500',					
					rownumbers: true,
					animate:true,
					collapsible:true,
					fitColumns:true,					
					url:'../SiteMenu/getEasyUiTree.json',
					method: 'post',
					idField: 'id',
					treeField: 'menuName',			
					showFooter:true,
					//onLoadSuccess: function () {$('#tg').treegrid('collapseAll')},
					toolbar: [{
						text: '新增导航', 
						iconCls: 'icon-add',
						handler: function(){	
							art.dialog.open('../SiteMenu/addInterface.htm?type=add',{
										title: '',
										lock:true,
									  	width: '50%',
									    height: '50%'												   												   
									});
						}
					},'-',{
						text: '新增内容', 
						iconCls: 'icon-page',
						handler: function(){	
							art.dialog.open('../SiteContent/addInterface.htm?type=addMenu',{
										title: '',
										lock:true,
									  	width: '95%',
									    height: '95%'												   												   
									});
						}
					}, '-', {
		                text : '展开',
		                iconCls : 'icon-redo',
		                handler : function() {
		                    var node = $('#tg').treegrid('getSelected');		                  
		                    if (node) {		                    	
		                        $('#tg').treegrid('expand', node.id);
		                    } else {		                    	
		                        $('#tg').treegrid('expandAll');
		                    }
		                }
		            }, '-', {
		                text : '折叠',
		                iconCls : 'icon-undo',
		                handler : function() {
		                    var node = $('#tg').treegrid('getSelected');
		                    if (node) {
		                        $('#tg').treegrid('collapseAll', node.id);
		                    } else {
		                        $('#tg').treegrid('collapseAll');
		                    }
		                }
		            }, '-', {
		                text : '刷新',
		                iconCls : 'icon-reload',
		                handler : function() {
		                    $('#tg').treegrid('reload');
		                }
		            }],					
					columns:[[
						{title:'id',field:'id',hidden:true,width:10},
						{title:'parentID',field:'parentID',hidden:true,width:10},
						{title:'名称',field:'menuName',width:100},		                
						{title:'类型',field:'categoryID',width:30,align:'center',
							formatter:function(value){									
					    		if(value=="0"){
					    			return '<font color="red">导航</font> ';
					    		}else{
					    			return '<font color="green">内容</font>';
					    		}						    							    	
					    	}	
						},
						{title:'路径',field:'url',width:100,
							//预览
							formatter:function(value,rec,index){	
								
								var urlNew='';
								if(rec.categoryID!=null && rec.categoryID=='1'){ //内容导航
				    				urlNew='/SiteIndex/content.htm?fk_menuId='+encode64(String(rec.id))+'&parNav='+rec.parentID;
									value=urlNew;
				    			}else{
					    			if(value!='' && value.indexOf('http')==-1){
					    				urlNew=value;
					    				if(urlNew.indexOf('?')==-1){
					    					urlNew=urlNew+'?parNav='+rec.parentID
					    				}else{
					    					urlNew=urlNew+'&parNav='+rec.parentID
					    				}
					    			}else{
					    				urlNew=value;
					    			}
				    			}
					    		var html='<a href="<%=basePath %>'+urlNew+'" target="_blank"><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a>'+value;
						    	return html;						    	
					    	}
						},		
						{title:'显示',field:'issue',width:20,align:'center',
						    formatter:function(value){						    	
						    	if (value){
						    		var ss;
						    		if(value=="1"){
						    			ss='<span disabled="disabled"><input type="checkbox" checked="checked" disabled="disabled"></span> ';
						    		}else{
						    			ss='<span disabled="disabled"><input type="checkbox" disabled="disabled"></span> ';
						    		}
							    	return ss;
						    	} else {
							    	return '';
						    	}
					    	}
						},
						{title:'位置',field:'typeID',width:20,align:'center',							
							formatter:function(value){									
					    		if(value=="0"){
					    			return '<font color="red">顶部</font> ';
					    		}else{
					    			return '<font color="blue">底部</font>';
					    		}						    							    	
					    	}	
						},		
						{title:'排序',field:'sortID',width:20,align:'center'},
						{field:'opt',title:'操作',width:100,align:'left',  
		                    formatter:function(value,rec,index){
		                    	
		                    	var up='<a title="上移" href="#" onclick="UpDown(\''+ rec.id + '\','+(Number(rec.sortID)-1)+')">' +
		                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/up.gif" alt="Up"></a>&nbsp;&nbsp;';
		                    			
                    			var down='<a title="下移" href="javascript:UpDown(\''+ rec.id + '\','+(Number(rec.sortID)+1)+')">' +
                    					'<img src="<%=basePath %>pages/Admin/Images/Icon/down.gif" alt="Down"></a>&nbsp;&nbsp;';
                   			
		                    	var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\',\''+rec.categoryID+'\')"  href="#">'+
		                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
		                    	
		                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\',\''+rec.categoryID+'\')"  href="#">'+
		                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';
		                        
		                        // 判断是否 parentID=0 则有增加 下一级的 按钮
		                        var add="",addContent="";
		                        if(rec.parentID==0){
		                        	add='<a title="新增子级" onclick="addSub(\''+ rec.id + '\')" href="#">'+
		                        			'<img src="<%=basePath %>pages/Admin/Images/Icon/add.gif" alt="Add"></a>&nbsp;&nbsp;';
		                        			
		                        	addContent='<a title="新增二级内容" onclick="addSubContent(\''+ rec.id + '\')" href="#">'+
                        			'<img src="<%=basePath %>pages/Admin/Images/Icon/page.gif" alt="Add"></a>';
		                        	
		                        }		                          
		                        return up+down+edit+dele+add+addContent;  
		                    }  
		                 }  
						
					]]				
				});
			})
			
			//排序 
			function UpDown(pkMenu,newSort){  								
				$.ajax({  
					type: "POST",  
			        url: '../SiteMenu/update.json', 
		    	    data:{  
		    	    	  id:pkMenu,
		    	    	  SortID:newSort,
		    	    	  type:'upDown'
		    	    },  
		    	    type:'post',  
		    	    cache:false,  
		    	    dataType:'json',  
		    	    success:function(map) {  
		    	    	if(map.success){		    	    		
		    	    		$('#tg').treegrid('reload');
		    	    	}		    	    	    	           
		    	    },  
		    	     error : function() {  
		    	          alert("异常！");  
		    	     }  
		    	});					
	           
	        } 
			
			function del(index,categoryID){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {	
				    	if(categoryID==1){ //内容导航
				    		$.ajax({
								type:'POST',
								dataType:'json',
								async:false,
								url:'../SiteContent/delete.json?type=deleMenu',
								data:{ids:index,delSub:true},
								success:function(data){
									if(data.success=true){									
										art.dialog.alert('删除成功！');
										window.location.reload();  
										
									}else{
										art.dialog.alert('删除失败，请联系管理员！');
									}
								}
							});
				    	}else{
				    		$.ajax({
								type:'POST',
								dataType:'json',
								async:false,
								url:'../SiteMenu/delete.json',
								data:{ids:index,delSub:true},
								success:function(data){
									if(data.success=true){									
										art.dialog.alert('删除成功！');
										window.location.reload();  
										
									}else{
										art.dialog.alert('删除失败，请联系管理员！');
									}
								}
							});
				    	}						
				    },
				    cancelVal: '取消',
				    cancel: true //为true等价于function(){}
				});
			
          	} 
			
			function edit(index,categoryID){  //编辑				
				if(categoryID==1){ //内容导航
					art.dialog.open('../SiteContent/updateInterface.htm?type=editMenu&fk_menuId='+index,{
						title: '',
						lock:true,
					  	width: '95%',
					    height: '95%'												   												   
					});
				}else{//菜单导航
					art.dialog.open('../SiteMenu/updateInterface.htm?type=edit&id='+index,{
						title: '',
						lock:true,
					  	width: '50%',
					    height: '50%'												   												   
					});
				}
				
          	} 
			
			function addSub(index){  //新增子集
				art.dialog.open('../SiteMenu/addInterface.htm?type=addSub&parentID='+index,{
					title: '',
					lock:true,
				  	width: '50%',
				    height: '50%'												   												   
				});
          	} 
			
			function addSubContent(index){  //新增二级内容导航
				art.dialog.open('../SiteContent/addInterface.htm?type=addSub&parentID='+index,{
					title: '',
					lock:true,
				  	width: '95%',
				    height: '95%'												   												   
				});
          	} 
			
			
			
			
		</script>	
	</head>
	<body>
		<div>					
			<table id="tg" width="100%" height="100%"></table>				
		</div>
	</body>
</html>